package com.ruoyi.web.controller.edh;

import java.math.BigDecimal;
import java.util.List;

import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.exception.user.CaptchaException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.edh.domain.EdhCommissionMix;
import com.ruoyi.edh.service.IEdhCommissionMixService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.smartcardio.CardException;

/**
 * 易订货-组建团队收益占比Controller
 *
 * @author xxx
 * @date 2020-09-23
 */
@RestController
@RequestMapping("/edh/commission")
@Api(description = "易订货-组建团队收益占比")
public class EdhCommissionMixController extends BaseController {
    @Autowired
    private IEdhCommissionMixService edhCommissionMixService;

    /**
     * 查询易订货-组建团队收益占比列表
     */
    @PreAuthorize("@ss.hasPermi('edh:mix:list')")
    @GetMapping("/list")
    @ApiOperation("易订货-组建团队收益占比列表")
    public TableDataInfo list(EdhCommissionMix edhCommissionMix) {
        startPage();
        List<EdhCommissionMix> list = edhCommissionMixService.selectEdhCommissionMixList(edhCommissionMix);
        return getDataTable(list);
    }

    /**
     * 导出易订货-组建团队收益占比列表
     */
    @PreAuthorize("@ss.hasPermi('edh:mix:export')")
    @Log(title = "易订货-组建团队收益占比", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出易订货-组建团队收益占比列表")
    public AjaxResult export(EdhCommissionMix edhCommissionMix) {
        List<EdhCommissionMix> list = edhCommissionMixService.selectEdhCommissionMixList(edhCommissionMix);
        ExcelUtil<EdhCommissionMix> util = new ExcelUtil<EdhCommissionMix>(EdhCommissionMix.class);
        return util.exportExcel(list, "mix");
    }

    /**
     * 获取易订货-组建团队收益占比详细信息
     */
    @PreAuthorize("@ss.hasPermi('edh:mix:query')")
    @GetMapping
    @ApiOperation("获取易订货-组建团队收益占比详细信息")
    public AjaxResult getInfo(Long id) {
        return AjaxResult.success(edhCommissionMixService.selectEdhCommissionMixById(id));
    }

    /**
     * 新增易订货-组建团队收益占比
     */
    @PreAuthorize("@ss.hasPermi('edh:mix:add')")
    @Log(title = "易订货-组建团队收益占比", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增易订货-组建团队收益占比")
    public AjaxResult add(@RequestBody EdhCommissionMix edhCommissionMix) {
        return toAjax(edhCommissionMixService.insertEdhCommissionMix(edhCommissionMix));
    }

    /**
     * 修改易订货-组建团队收益占比
     */
    @Log(title = "易订货-组建团队收益占比", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改易订货-组建团队收益占比")
    public AjaxResult edit(@RequestBody EdhCommissionMix edhCommissionMix) {
        BigDecimal mix = edhCommissionMix.getMix();
        if (mix.compareTo(BigDecimal.valueOf(1)) == 1 || mix.compareTo(BigDecimal.valueOf(0)) == -1) {
            throw new CustomException("设置组队收益占比请大于0%小于100%");
        }
        return toAjax(edhCommissionMixService.updateEdhCommissionMix(edhCommissionMix));
    }

    /**
     * 删除易订货-组建团队收益占比
     */
    @PreAuthorize("@ss.hasPermi('edh:mix:remove')")
    @Log(title = "易订货-组建团队收益占比", businessType = BusinessType.DELETE)
    @DeleteMapping
    @ApiOperation("删除易订货-组建团队收益占比")
    public AjaxResult remove(Long[] ids) {
        return toAjax(edhCommissionMixService.deleteEdhCommissionMixByIds(ids));
    }
}
